package applet;

import java.applet.Applet;
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Event;
import java.awt.Frame;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.metal.MetalLookAndFeel;

import applet.configurationManagement.ConfigurationManager;
import applet.connection.ConnectionManager;
import applet.logic.MediaModule;

/**
 * Initial calls for creating and managing the mediaServer.
 * Containts the testing functions and the evaluation processes for the creation of the instances for the media management
 * @version 0.1 (Development-Early Alpha)
 * @author Gonzalo Canelada Purcell
 * @date 28 September 2009
 */
public class InitiateC extends Applet{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2688796023965449577L;
	/**
	 * Handles the configuration information stored in the local file
	 */
	private ConfigurationManager configM = null;
	/**
	 * Handles the communications between the ApplicationServer and the clients
	 */
	private ConnectionManager connM = null;
	/**
	 * Handles the media streamer instance
	 */
	private MediaModule mediaM = null;
	examplePanel ep = null;
	
	public InitiateC(String user) {

		Frame f = new exampleFrame();
		ep = new examplePanel();
		f.add(ep);
		configM = createConfigurationManager(user);
		mediaM = createMediaModule(configM);
		connM = createConnectionmanager(configM,mediaM);
		connM.sendMessages();
	}
	
    public void init() {
		setLayout(new BorderLayout());
	}

    public void destroy() {
    }

    public void start() {
	ep.setEnabled(true);
    }

    public void stop() {
	ep.setEnabled(false);
    }

    public void processEvent(AWTEvent e) {
        if (e.getID() == Event.WINDOW_DESTROY) {
            System.exit(0);
        }
    }

    public static void main(String args[]) {
    	new InitiateC(null);
    }

    public String getAppletInfo() {
        return "A player for UnivTube Streaming service";
    }
	
	private ConfigurationManager createConfigurationManager(String u){
		return  new ConfigurationManager(u);
	}

	private ConnectionManager createConnectionmanager(ConfigurationManager configM,MediaModule medM){
		return new ConnectionManager(configM.get_config(),medM);
	}
	
	private  MediaModule createMediaModule(ConfigurationManager configM){
		return new MediaModule(configM.get_config());
	}
	
}
